How do I open a file for writing(multiple times)

In DOORS, how do I open up a file for writing? I understand and use this:

Stream out = write strFilename
The issue here is that I have a recursive script that needs to search through a directory(and subdirectories) for all of the modules below. I need to open each module, perform an action(write the actions data to a file), close the module and continue to the next module.
I wish to keep the file open until all data is written.
Is this possible?

Thank you for any help.
Gedinfo - Sat Feb 12 11:50:44 EST 2011

Re: How do I open a file for writing(multiple times)
ReinholdLauer - Mon Feb 14 02:36:53 EST 2011

One possible solution could be to declare the Stream public, open the steam before the recursive function is called the first time, and close the steam after the first call returns. All you do in the recursive function is to write to the file.

Re: How do I open a file for writing(multiple times)
llandale - Mon Feb 14 11:16:16 EST 2011

Yes the Stream could be a global variable, opened for write once. You could also pass the Stream variable into all your functions. You could also open for write then close the stream at the start of your program which erases the file, then inside your recursive algorithm open the stream "append", write, then close, which will append the results.

1st and 2nd options will run quite a bit faster than continually appending the file.

  • Louie

Re: How do I open a file for writing(multiple times)
Gedinfo - Mon Feb 14 11:20:54 EST 2011

llandale - Mon Feb 14 11:16:16 EST 2011
Yes the Stream could be a global variable, opened for write once. You could also pass the Stream variable into all your functions. You could also open for write then close the stream at the start of your program which erases the file, then inside your recursive algorithm open the stream "append", write, then close, which will append the results.

1st and 2nd options will run quite a bit faster than continually appending the file.

  • Louie

Thank you for this feedback. I have searched the DXL help, and do not see exactly how I make a global variable(I am opting for the first two options).

Re: How do I open a file for writing(multiple times)
llandale - Mon Feb 14 11:51:04 EST 2011

Gedinfo - Mon Feb 14 11:20:54 EST 2011
Thank you for this feedback. I have searched the DXL help, and do not see exactly how I make a global variable(I am opting for the first two options).

Just scribbled this down, didn't try it.

Stream    g_stOutput   
// Global variable, not defined inside any function string    NameSomeWindowsFile = 
"c:/MyFolder/MyReports/MyRecursiveReport.txt"     

void    MyFunction(Object obj) 
{   g_stOutput << number(obj) 
"\t" identifier(obj) 
"\n"  
// Global variable used here 
}   

void    MyRecursiveFunction(Object obj) 
{    Object oChild MyFunction(obj) 

for oChild in obj 

do 
{  MyRecursiveFunction(oChild) 
} 
}   

void   DoModule(Module mod) 
{    Object oTop 

for oTop in top(mod) 

do 
{  MyRecursiveFunction(oTop) 
} 
}   

void   ProcessFolder(Folder fld) 
{     Item itm Module mod Skip   skpItems = createString()  
// used to put items alphabetically sorted 
// [1] Get items in the folder 

for itm in fld 

do 
{  

if (!isDeleted(itm)) put(skpItems, name(itm), itm) 
} 
// [2] process modules in the folder 

for itm in skpItems 

do 
{  

if (type(itm) == 
"Formal") 
{  mod = read(fullName(itm), false, 

true) DoModule(mod) close(mod) 
} 
} 
// [3] recurse sub-folders and projects 

for itm in skpItems 

do 
{  

if (type(itm) == 
"Folder" or type(itm) == 
"Project") ProcessFolder(folder(fullName(itm))) 
} delete(skpItems) 
}   

void  DoFolder(Folder fld) 
{    g_stOutput = write(NameSomeWindowsFile) ProcessFolder(fld) close(g_stOutput) system(
"Notepad.exe " NameSomeWindowsFile) 
} DoFolder(current Folder)